package nz.co.doherty.gwtpbreadcrumbs.client;

import nz.co.doherty.gwtpbreadcrumbs.client.i8n.ClientMessages;

import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.inject.Inject;
import com.philbeaudoin.gwtp.mvp.client.EventBus;
import com.philbeaudoin.gwtp.mvp.client.proxy.PlaceManagerImpl;
import com.philbeaudoin.gwtp.mvp.client.proxy.TokenFormatter;

public class ClientPlaceManager extends PlaceManagerImpl {

	private final ClientMessages messages;

	@Inject
	public ClientPlaceManager(final EventBus eventBus,
			final TokenFormatter tokenFormatter,
			
			ClientMessages messages) {
		super(eventBus, tokenFormatter);

		// TODO These should be injected when GIN supports toInstance injection
		this.messages = messages;
	}

	@Override
	public void revealDefaultPlace() {
		History.newItem(NameTokens.home);
	}

	@Override
	public void revealErrorPlace(String invalidHistoryToken) {
		Window.alert(messages.invalidHistoryToken(invalidHistoryToken));
	}
}
